package com.example;

import com.example.beans.Product;
import com.example.beans.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
    public static void main(String[] args) {
        // 1. 加载Spring配置文件，初始化IOC容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        
        // 2. 从容器中获取Product bean
        Product product = (Product) context.getBean("product");
        System.out.println("获取到的Product Bean: " + product);
        
        // 3. 从容器中获取Student bean
        Student student = (Student) context.getBean("student");
        System.out.println("获取到的Student Bean: " + student);
        
        // 4. 获取通过构造函数配置的Product bean
        Product laptop = (Product) context.getBean("laptop");
        System.out.println("获取到的Laptop Bean: " + laptop);
        
        // 5. 关闭容器
        ((ClassPathXmlApplicationContext) context).close();
    }
}